/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxinline.servico;

import br.com.foxinline.modelo.Lancamento;
import br.com.foxinline.modelo.Projeto;
import java.math.BigDecimal;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author laverson
 */
@Stateless
public class LancamentoServico extends ServicoGenerico<Lancamento> {

    public LancamentoServico() {
        super(Lancamento.class);
    }

    public List<Lancamento> getLancamento(Projeto p) {
        String sql = "SELECT l FROM Lancamento l JOIN l.projeto p WHERE p.id = :projeto order by l.id desc ";

        Query query = getEntityManager().createQuery(sql);
        query.setParameter("projeto", p.getId());
        return (List<Lancamento>) query.getResultList();
    }

    public BigDecimal getValoresLancamento(Projeto p) {
        String sql = "SELECT sum(l.valor) FROM Lancamento l JOIN l.projeto p WHERE p.id = :projeto ";

        Query query = getEntityManager().createQuery(sql);
        query.setParameter("projeto", p.getId());
        return (BigDecimal) query.getSingleResult();
    }
}
